extern crate warp;

#[derive(serde::Serialize)]
pub struct ResponseContent<T> {
	pub status: i32,
	pub msg: String,
	pub data: T,
}

#[macro_export]
macro_rules! make_resp {
	($status: expr, $msg: expr, $data: expr) => {
		return warp::reply::with_status(warp::reply::json(&basic::ResponseContent {
			status: $status,
			msg: $msg,
			data: $data,
		}), warp::http::StatusCode::OK)
	};
}

#[macro_export]
macro_rules! require_token {
	($authorization: expr) => {
		if $authorization != *crate::core::config::TOKEN.lock().unwrap() {
			return warp::reply::with_status(warp::reply::json(&basic::ResponseContent {
				status: 1,
				msg: "invalid TOKEN".to_string(),
				data: (),
			}), warp::http::StatusCode::FORBIDDEN);
		}
	};
}

#[macro_export]
macro_rules! internal_error {
	($reason: expr) => {
		return warp::reply::with_status(warp::reply::json(&basic::ResponseContent {
			status: 2,
			msg: $reason,
			data: (),
		}), warp::http::StatusCode::INTERNAL_SERVER_ERROR)
	};
}
